package cn.jaychang.demo5.gateway.config.redis;

import cn.jaychang.demo5.common.model.constant.SysConstant;
import com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * @author jaychang
 * @since 2024/5/31
 **/
@Component
@Deprecated
public class InitRedisConfig {
    @Autowired
    private RedisTemplate<String,Object> redisTemplate;

    /**
     * 初始化 url权限=》角色列表 redis缓存
     */
    @PostConstruct
    public void init(){
        // TODO 这里需改成调用RPC服务查每个url所需的角色列表，然后放到redis中
        redisTemplate.opsForHash().put(SysConstant.OAUTH_URLS,"/order/login/info", Lists.newArrayList("ROLE_admin","ROLE_user"));
        // "/order/login/admin" 仅 ROLE_admin角色可以访问
        redisTemplate.opsForHash().put(SysConstant.OAUTH_URLS,"/order/login/admin", Lists.newArrayList("ROLE_admin"));
        redisTemplate.opsForHash().put(SysConstant.OAUTH_URLS,"/order/info", Lists.newArrayList("ROLE_admin","ROLE_user"));
        redisTemplate.opsForHash().put(SysConstant.OAUTH_URLS,"/order/listByUserId", Lists.newArrayList("ROLE_admin","ROLE_user"));
        redisTemplate.opsForHash().put(SysConstant.OAUTH_URLS,"/oauth/logout", Lists.newArrayList("ROLE_admin","ROLE_user"));
    }

}
